/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package WSpkg;

import ejb.Capo;
import ejb.CapoFacade;
import java.util.List;
import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import session.GestCapoLocal;
import session.GestOutfitLocal;
import session.GestUtenteLocal;


/**
 *
 * @author Gemma
 */
@WebService(serviceName = "WhatToWearWS")
public class WhatToWearWS {

    @EJB
    private GestUtenteLocal gestUtente;
    @EJB
    private GestCapoLocal gestCapo;
    @EJB
    private GestOutfitLocal gestOutfit;
    @EJB
    private CapoFacade capoFacade;

    /**
     * Web service operation login
     *
     * @param mail
     * @param password
     * @return
     */
    @WebMethod(operationName = "login")
    public Boolean login(@WebParam(name = "mail") String mail,
            @WebParam(name = "password") String password) {
        return gestUtente.login_attempt(mail, password);
    }

    /**
     * Web service operation addUtente
     *
     * @param nome
     * @param mail
     * @param password
     * @return
     */
    @WebMethod(operationName = "addUtente")
    public int addUtente(@WebParam(name = "nome") String nome,
            @WebParam(name = "mail") String mail,
            @WebParam(name = "password") String password) {
        String gruppo = "USR";
        gestUtente.addUtente(nome, mail, password, gruppo);
        return 0;
    }

    /**
     * Web service operation Aggiungi capo
     *
     * @param idutente
     * @param base64
     * @return
     */
    @WebMethod(operationName = "AddCapo")
    public int AddCapo(@WebParam(name = "idutente") String idutente,
            @WebParam(name = "base64") String base64) {

        String categoria = null;
        String colore = null;
        String marca = null;
        String nome = null;
        String prezzo = null;
        String immagine = null;

        String appoggio = "";
        char[] img = ("data:image/jpeg;base64," + base64).toString().toCharArray();
        for (int k = 0; k < img.length; k++) {
            if (img[k] != '\n') {
                appoggio += img[k];
            }
        }

        String mail = idutente;
        gestCapo.addCapo(mail, categoria, colore, immagine,
                marca, nome, prezzo, appoggio.toCharArray());
        return 0;
    }

    /**
     * Web service operation aggiungi outfit
     *
     * @param idutente
     * @param base64
     * @return
     */
    @WebMethod(operationName = "AddOutfit")
    public int AddOutfit(@WebParam(name = "idutente") String idutente,
            @WebParam(name = "base64") String base64) {

        String appoggio = "";
        char[] img = ("data:image/jpeg;base64," + base64).toString().toCharArray();
        for (int k = 0; k < img.length; k++) {
            if (img[k] != '\n') {
                appoggio += img[k];
            }
        }

        String outfit = null;
        String mail = idutente;
        gestOutfit.addOutfit(mail, outfit, appoggio.toCharArray());
        return 0;
    }
    
    /**
     * Web service operation showcamerino
     * @param mail
     * @return
     */
    @WebMethod(operationName = "showCamerino")
    public Object[] showcamerino(@WebParam(name = "mail") String mail) {
        
       List<Capo> lista = capoFacade.findByID(mail);
       Object[] img = lista.toArray();     
       return img ;
    }

}
